<?php
include("Connections/elevate954.php");
include_once('functions.php');

mysql_select_db($database_elevate954, $elevate954);

if($_POST['function'] == 'workoutFilter'){	
	if(isset($_POST['catId']) && !empty($_POST['catId'])){
	  $id=$_POST['catId'];
	}else{
	  $id='0';
	}
	
	if(isset($_POST['pageId']) && !empty($_POST['pageId'])){
	  $pageId=$_POST['pageId'];
	}else{
	  $pageId='0';
	}
	
	$filterPage = $_POST['filterPage'];
	$pagePer = (int)$_POST['pagePer'];
	
	$pageLimit=$pagePer*$pageId;                
	$HTML='';$HTML2='';$content = '';
	
	if(isset($id) && !empty($id) && $id !=0){
		$get_image = "select * from WORKOUTS where CAT_ID=".$id." order by id desc limit $pageLimit,".$pagePer;
	}else{
		$get_image = "select * from WORKOUTS order by CAT_ID,id desc limit $pageLimit,".$pagePer;
	}
	$res_image = mysql_query($get_image);
	$count_gallery = mysql_num_rows($res_image);
	if($count_gallery > 0){
		$c=0;$lastCat=-1;
		
		if($id >= 0){
			if($id != 0)
				$imageCnt = "select * from WORKOUTS where CAT_ID=".$id;
			else
				$imageCnt = "select * from WORKOUTS";
			$resCnt = mysql_query($imageCnt);
			$cntImg = mysql_num_rows($resCnt);
	
			$paginationCount=getPagination($cntImg,$pagePer);
				
			$content .='<ul class="tsc_pagination tsc_paginationC tsc_paginationC01">';
				
				for($i=0;$i<$paginationCount;$i++){
					if($i == 0){ $sel = 'current'; }else{ $sel = ''; }
					$content .='<li id="'.$i.'_no" class="link">
		<a class="'.$sel.' '.$i.'_no" href="javascript:void(0)" onclick="changePagination(\''.$i.'\',\''.$i.'_no\','.$id.')">
						  '.($i+1).'
					  </a>
				</li>';
				}
			 
				$content .='<li class="flash"></li>
			</ul>';
		}
		
		$HTML .= '<ul id="list" class="image-grid threecol portfolio-content">';
		
		while($row_image = mysql_fetch_array($res_image))
		{
			if($row_image['CAT_ID'] != $lastCat){
				$get_workout_cat = "select * from WORKOUT_CATEGORY where id =".$row_image['CAT_ID'];
				$res_workout_cat = mysql_query($get_workout_cat);
				$row_workout_cat = mysql_fetch_array($res_workout_cat);
				$c++;
			}
			$lastCat = $row_image['CAT_ID'];
             
        $HTML .= '<li data-id="'.$c.'" data-type="'.str_replace(' ','_',$row_workout_cat['TITLE']).'">';

			if($row_image['MEDIA_TYPE'] == "VIDEO"){							
			$HTML .= '<div class="col-md-3 col-sm-4 mix category_1">
					<div class="mix-inner">
						<img class="img-responsive" src="/image_uploads/'.$row_image['THUMB'].'" alt="" width="100%" height="184px">
						<div class="mix-details">
							<h4>'.$row_image['TITLE'].'</h4>
							
							
							<!--<a class="mix-link"><i class="fa fa-link"></i></a>-->
							<a class="mix-preview fancybox-button fancybox fancybox.iframe" href="../members/video_page.php?id='.$row_image['id'].'" title="'.$row_image['TITLE'].'"><i class="fa fa-search"></i></a>
						</div>
					</div>
				</div>';
             }else if($row_image['MEDIA_TYPE'] == "image"){							
			$HTML .= '<div class="hover_image">
							<div class="col-md-3 col-sm-4 mix category_2">
								<div class="mix-inner">
									<img class="img-responsive" 
									src="/image_uploads/'.$row_image['THUMB'].'" alt="" width="100%" height="184px">
									<div class="mix-details">
										<h4>'.$row_image['TITLE'].'</h4>
										<!--<a class="mix-link"><i class="fa fa-link"></i></a>-->
										<a class="mix-preview fancybox-button" 
										href="/image_uploads/'.$row_image['IMAGE'].'" 
										title="'.$row_image['TITLE'].'" data-rel="fancybox-button">
										<i class="fa fa-search"></i></a>
									</div>
								</div>
							</div>
				  </div>';
             }
			$HTML .= '</li>';
		}
		$HTML .= '</ul>';
	}else{
		$HTML = '<div class="noData">No Data Found</div>';
	}
	
	if(isset($id) && !empty($id) && $id !=0){
		$get_image = "select * from WORKOUTS where CAT_ID=".$id." order by id desc limit $pageLimit,".$pagePer;
	}else{
		$get_image = "select * from WORKOUTS order by CAT_ID,id desc limit $pageLimit,".$pagePer;
	}
	$res_image = mysql_query($get_image);
	$count_gallery = mysql_num_rows($res_image);
	if($count_gallery > 0){
		$c=0;$lastCat=-1;
		
		$HTML2 .= '<ul id="list1" class="image-grid threecol portfolio-content">';
		
		while($row_image = mysql_fetch_array($res_image))
		{
			if($row_image['CAT_ID'] != $lastCat){
				$get_workout_cat = "select * from WORKOUT_CATEGORY where id =".$row_image['CAT_ID'];
				$res_workout_cat = mysql_query($get_workout_cat);
				$row_workout_cat = mysql_fetch_array($res_workout_cat);
				$c++;
			}
			$lastCat = $row_image['CAT_ID'];
             
        $HTML2 .= '<li data-id="'.$c.'" data-type="'.str_replace(' ','_',$row_workout_cat['TITLE']).'">';

			if($row_image['MEDIA_TYPE'] == "VIDEO"){							
			$HTML2 .= '<div class="col-md-6 col-sm-6 mix category_1">
					<div class="mix-inner">
						<img class="img-responsive" width="635" src="/image_uploads/'.$row_image['THUMB'].'" alt="" >
						<div class="mix-details">
							<h4>'.$row_image['TITLE'].'</h4>
							'.substr($row_image['TEXT'],0,350).'
							<!--<a class="mix-link"><i class="fa fa-link"></i></a>-->
							<a class="mix-preview fancybox-button fancybox fancybox.iframe" href="../members/video_page.php?id='.$row_image['id'].'" 
							title="'.$row_image['TITLE'].'" ><i class="fa fa-search"></i></a>
						</div>
					</div>
				</div>';
             }else if($row_image['MEDIA_TYPE'] == "image"){							
			$HTML2 .= '<div class="hover_image2">
							<div class="col-md-6 col-sm-6 mix category_2">
								<div class="mix-inner">
									<img class="img-responsive" 
									src="/image_uploads/'.$row_image['THUMB'].'" width="635" alt="" >
									<div class="mix-details">
										<h4>'.$row_image['TITLE'].'</h4>
										'.substr($row_image['TEXT'],0,350).'
										<!--<a class="mix-link"><i class="fa fa-link"></i></a>-->
										<a class="mix-preview fancybox-button" 
										href="/image_uploads/'.$row_image['IMAGE'].'" 
										title="'.$row_image['TITLE'].'" data-rel="fancybox-button">
										<i class="fa fa-search"></i></a>
									</div>
								</div>
							</div>
				  </div>';
             }
			$HTML2 .= '</li>';
		}
		$HTML2 .= '</ul>';
	}else{
		$HTML2 = '<div class="noData">No Data Found</div>';
	}
	
	echo json_encode(array($HTML,$content,$HTML2));
}




if($_POST['function'] == 'productFilter'){	


if(isset($_POST['pageId']) && !empty($_POST['pageId'])){
  $id=$_POST['pageId'];
}else{
  $id='0';
}

$pagePer = (int)$_POST['pagePer'];
$pageLimit= $pagePer*$id;                
$HTML='';$content = '';

if(isset($_POST['filterCat']) && !empty($_POST['filterCat']) && $_POST['filterCat'] !=0){
	$get_image = "select * from Products where Product_Cat_id=".$_POST['filterCat']." order by ProductID desc limit $pageLimit,".$pagePer;
}else{
	$get_image = "select * from Products order by Product_Cat_id,ProductID desc limit $pageLimit,".$pagePer;
}
$res_image = mysql_query($get_image);
$count_product = mysql_num_rows($res_image);
if($count_product > 0){
	$c=0;$lastCat=-1;
	
	if($_POST['filterCat'] >= 0){
		if($_POST['filterCat'] != 0)
			$imageCnt = "select * from Products where Product_Cat_id=".$_POST['filterCat'];
		else
			$imageCnt = "select * from Products";
		$resCnt = mysql_query($imageCnt);
		$cntImg = mysql_num_rows($resCnt);

		$paginationCount=getPagination($cntImg,$pagePer);
			
		$content .='<ul class="tsc_pagination tsc_paginationC tsc_paginationC01">';
			/*<li class="first link" id="first">
			<a  href="javascript:void(0)" onclick="changePagination(\'0\',\'first\','.$_POST['filterCat'].')">F i r s t</a>
			</li>';*/
			for($i=0;$i<$paginationCount;$i++){
		 		if($i == 0){ $sel = 'current'; }else{ $sel = ''; }
				$content .='<li id="'.$i.'_no" class="link">
			<a class="'.$sel.' '.$i.'_no" href="javascript:void(0)" onclick="changePagination(\''.$i.'\',\''.$i.'_no\','.$_POST['filterCat'].')">
					  '.($i+1).'
				  </a>
			</li>';
			}
		 
			/*'<li class="last link" id="last">
	<a href="javascript:void(0)" onclick="changePagination(\''.($paginationCount-1).'\',\'last\','.$_POST['filterCat'].')">L a s t</a>
			</li>*/
			$content .='<li class="flash"></li>
		</ul>';
	}
	
	$HTML .= '<ul id="list" class="image-grid threecol2 portfolio-content">';
	
	while($row_image = mysql_fetch_array($res_image))
	{
		if($row_image['Product_Cat_id'] != $lastCat){
			$get_product_cat = "select * from product_cat where Product_Cat_id=".$row_image['Product_Cat_id'];
			$res_product_cat = mysql_query($get_product_cat);
			$row_product_cat = mysql_fetch_array($res_product_cat);
			$c++;
		}
		$lastCat = $row_image['Product_Cat_id'];
		$formCart = (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; 
		$HTML .= '<li data-id="'.$c.'" data-type="'.str_replace(' ','_',$row_product_cat['name']).'">';
		
			$HTML .= ' <div class="hover_image2">
                       <a href="/images/products/'.$row_image['ProductThumb'].' rel="prettyPhoto" title=""><img src="/images/products/'.$row_image['ProductImage'].'" alt="" width="290" height="290"/></a>
                          </div>
						  <div class="text_box2">
                              <h4>'.$row_image["ProductName"].'</h4>'.$row_image["ProductShortDesc"].'<form name="ELEVATE954_1_ATC_'.$row_image["ProductID"].'" method="POST" 
	action="'.$_SERVER["PHP_SELF"].$formCart.'">
                                <h4>
                                  <input type="hidden" name="ELEVATE954_1_ID_Add" value="'.$row_image["ProductID"].'" >
                                  <input type="text" name="ELEVATE954_1_Quantity_Add" value="1" size="5" >
  &nbsp;&nbsp;                             Price: '.$row_image["ProductRetailPrice"].'&nbsp;&nbsp; 
                                  <input type="submit" class="button dark small" value="Add to Cart" name="ELEVATE954_1_ATC">
                                </h4> 
                            </form>
                       </div>';
                            
        
        $HTML .= '</li>';
	}
	$HTML .= '</ul>';
}else{

	$HTML = 'No Data Found';
}

echo json_encode(array($HTML,$content));

}